package com.leetcode.August;

/**
 * @Description: 209. 长度最小的子数组
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-24 09:33
 */
public class LC209长度最小的子数组 {
    public int minSubArrayLen(int target, int[] nums) {
        int left=0,sum=0,n=nums.length-1,ans=Integer.MAX_VALUE;
        for (int right  = 0; right  < n; right ++) {
            sum+=nums[right];
            while (sum-nums[left]>=target){
                sum-=nums[left];
            }
            if (sum>=target){
                ans=Math.min(ans,right-left+1);
            }
        }
        return ans<=n?ans:0;
    }
}
